# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: conftest.py
# Time: 14:13

import pytest
import allure
from common.utils.log_util import logger
from common.utils.http_util import RestClient
from common.utils.read_util import OperationIni
from common.utils.read_util import ReadFileData
from common.utils.file_util import get_data_json

@pytest.fixture(scope="session")
def ip():
    global ip
    ip = OperationIni("setting.ini").get_ini_file_path_section_data("host").get("api_root_url")
    yield ip

@pytest.fixture(scope="session")
def log():
    global log
    log = logger()
    return log

@allure.step("前置步骤 ==>> 清理数据")
def step_first():
    log.info("******************************")
    log.info("前置步骤开始 ==>> 清理数据")


@allure.step("后置步骤 ==>> 清理数据")
def step_last():
    log.info("后置步骤开始 ==>> 清理数据")


@allure.step("前置步骤 ==>> 管理员用户登录")
def step_login(username, password):
    log.info("前置步骤 ==>> 管理员 {} 登录，返回信息 为：{}".format(username, password))

@pytest.fixture(scope="session")
def login_fixture():
    file_path = get_data_json("api_url.json")
    url = ReadFileData().load_json(file_path).get("login_students")
    username = "niuhanyang"
    password = "aA123456"
    data = {
        "username":username,
        "passwd":password
    }
    res = RestClient(log,ip).post(url=url,data=data)
    step_login(username,password)
    return res.json()
